package com.compass.doctor.ui.home.viewmodel

import androidx.lifecycle.MutableLiveData
import com.compass.framework.model.DrugTabItem
import com.compass.framework.model.Inventory
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel

/**
 * Description： 药品相关viewModel
 * Date:2023/12/7 10:31
 */
class DrugViewModel :BaseViewModel() {

    val drugTabLiveData = MutableLiveData<MutableList<DrugTabItem>?>()
    val isPermitLiveData = MutableLiveData<Inventory?>()
    /**
     * 获取药品分类信息
     */
    fun getPharmacyInfo(drugName: String?="",drugType: Int?=null) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getPharmacyInfo(drugName,drugType)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                drugTabLiveData.value = null
            }
        }) {
            drugTabLiveData.value=it
        }

    }




    /**
     * 获取药品库存
     */
    fun getDrugInventory(id: String,num:String) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getDrugInventory(id,num)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                isPermitLiveData.value=null
            }
        }) {
            isPermitLiveData.value=it
        }
    }
}